home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2166 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.7 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: David Reiss <reiss@astro.washington.edu>
  3. Newsgroups: comp.sys.mac.oop.misc,comp.sys.mac.programmer.codewarrior,comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: [Q] [enums] class_ID as enum is basically useless? Why not GetClassID()?
  5. Date: 15 Jan 1996 22:28:02 -0000
  6. Organization: http://www.astro.washington.edu
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4dekdi$qs2@netlab.cs.rpi.edu>
  10. References: <4dboiv$rlm@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: 15 Jan 1996 22:12:57 GMT
  13.  
  14. The class_ID is meant to NOT be virtual...this way it can be used to
  15. register the stream-constructor static routines with URegistrar allowing
  16. easy construction using Constructor.  I suppose a static GetClassID() 
  17. routine would be ok, but there's no real difference there.  If you
  18. want to do a 
  19.  
  20. myPane->GetClassID()
  21.  
  22. kind of call, you should probably use RTTI (as far as I've been told) to
  23. determine what kind of object your myPane is.  As far as I know, there's
  24. no other way, other than modifying the PP code itself.
  25.  
  26. -David
  27.  
  28. richard@moriarty.com (Richard Jason Lyders) wrote:
  29. >HELP! Suggestions are MOST WELCOME!
  30. >
  31. >Why would someone use an enum for a class_ID in a class library? Why not
  32. >simply provide a GetClassID() function for each class? That would be so
  33. >much simpler and so much more useful!
  34. >
  35. >I don't seem to be able to use the enum class_ID  to find out what class
  36. >an object is because class_ID isn't "virtual" like a function. If you have
  37. >an object of a class that is derived from a base class, and you are
  38. >referencing that object using the base pointer, then class_ID does not
  39. >tell you the class of the object, it tells you the class of the pointer.
  40. >What god is this? I know what class the pointer is because I cast it
  41. >myself! Duh?
  42. >
  43. >This means that I don't seem to be able to create a routine that uses a
  44. >base class as a pointer to any of that base class's derived classes. . .
  45. >because in that routine I need to know exactly what the class_id is of the
  46. >REAL object rather than the class_ID of the base object (which is pretty
  47. >darn obvious because it never changes).
  48. >
  49. >I did not expect to run into this problem. Is this a limitation? an error
  50. >on my part? Is there another way to find out the actual class of an object
  51. >without using a class_ID enum that really will give me the correct
  52. >class_ID?
  53. >
  54. >So , by using an enum . . .whatever you type cast a pointer as. . . that's
  55. >the class ID that you get. . . so it isn't any better than a compiler
  56. >#define as far as I am trying to use it.
  57. >
  58. >If you check out my code example below. . .you will see my confusion as to
  59. >why a class_ID enum would be used . . . and I hope ther is another way of
  60. >finding out an object's actual class ID.
  61. >
  62. >PS: and no, it is not possible to give each class a GetClassID routine
  63. >because I am having this problem with the Metrowerks PowerPlant class
  64. >library and I don't think it is very acceptible to  just go around
  65. >changing the inner workings of a class library.
  66. >
  67. >class LPane {
  68. >   public:
  69. >      enum { class_ID = 'pane' };
  70. >      LPane() {};
  71. >      ~LPane() {}; 
  72. >};
  73. >
  74. >class LView : public LPane {
  75. >   public:
  76. >      enum { class_ID = 'view' };
  77. >      LView() {};
  78. >      ~LView() {};
  79. >};
  80. >
  81. >void main (void) {
  82. > LPane aPane;
  83. > LView aView;
  84. > LPane * aPanePtr = &aPane;
  85. > LView * aViewPtr =  &aView;
  86. > LPane * aPanePtr2 = (LPane*)aViewPtr;
  87. > long aPaneClassID = aPanePtr->class_ID;    // = 'pane' (obviously) 
  88. > long aViewClassID = aViewPtr->class_ID;    // = 'view' (obviously)
  89. > long aWhichClassID = aPanePtr2->class_ID;  // = 'pane' ********* why?
  90. >**********
  91. >}
  92. >
  93. >/*                                   
  94. >                                     ?
  95. > ___  o     _             _         /
  96. >| o \ _ ___| |_ ___ _ _ _| |    /"""\
  97. >|   /| | __)   | o | '_| o |    |~'~|       
  98. >|_|_\|_\___)_|_|_|_|_| \___|    \ - /     
  99. >.---------------------------------^----. 
  100. >| Richard Jason Lyders  Houston, Texas |
  101. >|         richard@moriarty.com         |
  102. >'-----------------------------OOo----oOO
  103. >                                |=[]=|       
  104. >                                /_/\_\            
  105. >                               oOO  OOo
  106. >
  107. >*/
  108. >
  109. >      [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  110. >      [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  111. >      [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  112. >      [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  113.  
  114.  
  115.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  116.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  117.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  118.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  119.